classdef TestDotsTransaction < dotsTestCase
    
    properties
        original;
    end
    
    methods
        function self = TestDotsTransaction(name)
            self = self@dotsTestCase(name);
        end
        
        function setUp(self)
            self.setUp@dotsTestCase;
            
            self.original = dotsTransaction.newTransactionStruct;

            props = fieldnames(self.original);
            for ii = 1:length(props)
                p = props{ii};
                if isnumeric(p)
                    val = 1234567890;
                elseif ischar(p)
                    val = 'abcde fghij.1234567890;';
                elseif islogical(p)
                    val = true;
                else
                    val = [];
                end
                self.original.(p) = val;
            end
        end
        
        function tearDown(self)
            self.tearDown@dotsTestCase;
        end
        
        function testToFromString(self)
            % toString and fromString are actually deprecated
            s = dotsTransaction.toString(self.original);
            txn = dotsTransaction.newTransactionStruct;
            reproduction = dotsTransaction.fromString(txn, s);
            assertEqual(self.original, reproduction, 'failed to reproduce transaction from string');
        end
        
        % interesting information, but not really unit tests
        
        % function testToStringTime(self)
        %     txn = self.original;
        %
        %     n = 100;
        %     times = zeros(1,n);
        %     for ii = 1:n
        %         tic;
        %         string = txn.toString;
        %         times(ii) = toc;
        %     end
        %     disp([mean(times(2:end)), std(times(2:end))])
        % end
        %
        % function testFromStringTime(self)
        %     txn = self.original;
        %     string = txn.toString;
        %
        %     n = 100;
        %     times = zeros(1,n);
        %     for ii = 1:n
        %         tic;
        %         txn = txn.fromString(string);
        %         times(ii) = toc;
        %     end
        %     disp([mean(times(2:end)), std(times(2:end))])
        % end
    end
end